import { reactive, ref } from "@vue/reactivity";
import { useRouter } from "vue-router";
export const useForm = function () {
  const router = useRouter();
  const ruleForm = ref(null);
  const onSubmit = function () {
    ruleForm.value.validate().then(() => {
      router.push({
        path: "/index",
      });
    });
  };
  const resetForm = function () {
    ruleForm.value.resetFields();
  };
  const form = reactive({
    name: "",
    password: "",
    check: false,
  });
  const rule = reactive({
    name: [
      {
        required: true,
        message: "Please input Activity name",
        trigger: "blur",
      },
      {
        min: 3,
        max: 5,
        message: "Length should be 3 to 5",
        trigger: "blur",
      },
    ],
    password: [
      {
        required: true,
        message: "Please input Activity password",
        trigger: "blur",
      },
      {
        min: 3,
        max: 32,
        message: "Length should be 3 to 5",
        trigger: "blur",
      },
    ],
    password1: [
      {
        required: true,
        message: "Please input  password",
        trigger: "blur",
      },
      {
        min: 3,
        max: 5,
        message: "Length should be 3 to 5",
        trigger: "blur",
      },
    ],
    yzm: [
      {
        required: true,
        message: "Please input yzm",
        trigger: "blur",
      },
    ],
  });
  return {
    form,
    rule,
    onSubmit,
    resetForm,
    ruleForm,
  };
};
